﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PreeRegisterModel;
using System.Data;
using PreeRegisterDAL;

namespace PreeRegisterBLL
{
    public class WorkGetcountBLL
    {
        /// <summary>
        /// 排班号源统计
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static WorkGetcountResponseBodyModel GetWorkCount(WorkGetcountRequestBodyModel request)
        {
            try
            {
                //查询排班数量统计
                WorkGetcountResponseBodyModel workGetcountResponseBodyModel = new PreeRegisterModel.WorkGetcountResponseBodyModel();

                if (request.workdate.Trim()=="")
                {
                    return null;
                }

                string [] arrWorkDate=request.workdate.Split(new char[]{','});

                string strWorkDate="";

                foreach(string WorkDate in arrWorkDate)
                {
                    strWorkDate+="'"+WorkDate+"',";
                }
                if (strWorkDate.Trim().Length>0)
                {
                    strWorkDate=strWorkDate.Remove(strWorkDate.Length-1);
                }

                DataSet ds = WorkGetcountDAL.GetWorkCountInfo(strWorkDate);

                //赋值排班数量实体
                List<DeptsWorkCountModel> DeptsWorkCountModel_list = new List<DeptsWorkCountModel>();

                foreach (DataRow drWorkCount in ds.Tables["WorkCount"].Rows)
                {
                    DeptsWorkCountModel deptsWorkCountModel = new DeptsWorkCountModel();
                    deptsWorkCountModel.deptid = drWorkCount["ideptid"].ToString();
                    deptsWorkCountModel.workcount = drWorkCount["workcount"].ToString();
                    deptsWorkCountModel.tcount = drWorkCount["tcount"].ToString();
                    deptsWorkCountModel.mcount = drWorkCount["mcount"].ToString();
                    deptsWorkCountModel.acount = drWorkCount["acount"].ToString();

                    DeptsWorkCountModel_list.Add(deptsWorkCountModel);
                }

                workGetcountResponseBodyModel.hospid = VariableBLL.HospitalId;
                workGetcountResponseBodyModel.depts = DeptsWorkCountModel_list;

                //返回
                return workGetcountResponseBodyModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
